package com.adxon.servlet;

import com.adxon.MsgException;
import com.adxon.data.User;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.*;

@SuppressWarnings("serial")
public class SignupServlet extends ServletBase{
	public void doGet(HttpServletRequest req,HttpServletResponse resp)
			throws IOException,ServletException{
		String m=null;
		User u=new User();
		try{
			u.setAll(req);
			if(req.getAttribute("ok")!=null){
				u.commit();
				resp.sendRedirect("/");
				return;
			}
		}catch(MsgException e){
			m=e.getMessage();
		}
		u.getAll(req);
		setAttributes(req,"Sign up");
		req.setAttribute("Message",m);
		forward("signup.jsp",req,resp);
	}
	public void doPost(HttpServletRequest req,HttpServletResponse resp)
			throws IOException,ServletException{
		doGet(req,resp);
	}
}